﻿<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="UploadFile.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title>Untitled Page</title>
    
    
    <script >
     var x = false;
     var total = 1;
     function addFileUpload()
     {
        if (!document.getElementById || !document.createElement)
            return;
        var uploadarea = document.getElementById("UploadArea");
        if (!uploadarea)
            return;
         if (!addFileUpload.lastAssignedId)
            addFileUpload.lastAssignedId = 100;            
       
      
        var newdiv = document.createElement('div');
        newdiv.innerHTML = '<input id="FileFile'+addFileUpload.lastAssignedId+'" name="FileField"'+addFileUpload.lastAssignedId+' size =60 type="file" /> <a href=\'#\' onclick=\'removeElement('+addFileUpload.lastAssignedId+')\'>Delete</a>';        
        newdiv.setAttribute('id',"uploaddiv"+addFileUpload.lastAssignedId);
        uploadarea.appendChild(newdiv);
        addFileUpload.lastAssignedId ++;        
        total++;
        if (total == 5)
        {
           var btnaddd = document.getElementById("btnAddUpload");
           btnaddd.style.visibility = "hidden";
        }
       
        return false;
     }
     
     function removeElement(divNum)
     {
        var d = document.getElementById('UploadArea');
        var olddiv = document.getElementById("uploaddiv"+divNum);
        d.removeChild(olddiv);          
        total--;
        if (total < 5)
        {
         var btnaddd = document.getElementById("btnAddUpload");
           btnaddd.style.visibility = "visible";
        }
     }
     
     
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>    
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        
        <p id="UploadArea">
        <input id="File1" type="file" size="60" runat="server"/>
        </p>    
        <p >
        <input id="btnAddUpload"  name="btnAddUpload" type="button" value="Add File" onclick="addFileUpload();" />
        </p>
    </div>
        
   <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    
    
    
    
    </form>
</body>
</html>
